package cn.yunhe.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

/**
 * Created by zs on 2018/1/5.
 */
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    //SpringIOC环境配置
    protected Class<?>[] getRootConfigClasses() {
        //配置SpringIOC资源
        return new Class<?>[]{RootConfig.class};
    }

    //DispatcherServlet环境配置
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{WebConfig.class};
    }

    protected String[] getServletMappings() {
        return new String[]{"*.do"};
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic dynamic) {
        //配置上传文件的路径
        String filepath = "e:/IdeaProjects/redpackage/uploads";
        //单个上传大小和总大小
        Long singleMax = (long) (5 * Math.pow(2, 20));
        Long totaleMax = (long) (10 * Math.pow(2, 20));
        //设置上传文件的配置
        dynamic.setMultipartConfig(new MultipartConfigElement(filepath, singleMax, totaleMax, 0));

    }
}
